import axios from "axios";


class Request {
    async get(url: string, data: any = {}, config: any = {}) {

        const uptoken = (config.uptoken == undefined) ? true : config.uptoken

        //调用axios的get请求
        const resdata = await axios.get(url, {
            params: data,
            headers: uptoken ? {
                // 将本地的token设置到请求头中携带发送请求
                'authorization': 'Bearer ' + localStorage.getItem('token'),
                "Content-type": "multipart/form-data",
            } : {},
            ...config
        });
        return resdata
    }

    async post(url: string, data: any = {}, config: any = {}) {
        const uptoken = (config.uptoken == undefined) ? true : config.uptoken
        const resdata = await axios.post(url, data, {
            headers: uptoken ? {
                'authorization': 'Bearer ' + localStorage.getItem('token'),
                // 使用默认Content-type请求头
            } : {},
            ...config
        })
        return resdata
    }

}


const request = new Request();

export default request;
